package net.lab1024.smartadmin.module.business.gearboxSpeed.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.gearboxEfficiency.domain.entity.GearboxEfficiencyEntity;
import net.lab1024.smartadmin.module.business.gearboxSpeed.dao.GearboxSpeedDao;
import net.lab1024.smartadmin.module.business.gearboxSpeed.domain.dto.GearboxSpeedAddDTO;
import net.lab1024.smartadmin.module.business.gearboxSpeed.domain.dto.GearboxSpeedUpdateDTO;
import net.lab1024.smartadmin.module.business.gearboxSpeed.domain.dto.GearboxSpeedQueryDTO;
import net.lab1024.smartadmin.module.business.gearboxSpeed.domain.entity.GearboxSpeedEntity;
import net.lab1024.smartadmin.module.business.gearboxSpeed.domain.vo.GearboxSpeedVO;
import net.lab1024.smartadmin.module.business.gearboxSpeed.domain.vo.GearboxSpeedExcelVO;
import net.lab1024.smartadmin.util.SmartPageUtil;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ 变速箱速比参数 ]
 *
 * @author wuhq
 * @version 1.0
 * @company 汽车传动
 * @copyright (c)  汽车传动Inc. All rights reserved.
 * @date 2022-05-27 11:30:30
 * @since JDK1.8
 */
@Service
public class GearboxSpeedService {

    @Autowired
    private GearboxSpeedDao gearboxSpeedDao;

    /**
     * 根据id查询
     */
    public GearboxSpeedEntity getById(Long id){
        return  gearboxSpeedDao.selectById(id);
    }

    /**
     * 分页查询
     * @author wuhq
     * @date 2022-05-27 11:30:30
     */
    public ResponseDTO<PageResultDTO<GearboxSpeedVO>> queryByPage(GearboxSpeedQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<GearboxSpeedVO> voList = gearboxSpeedDao.queryByPage(page, queryDTO);
        PageResultDTO<GearboxSpeedVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author wuhq
     * @date 2022-05-27 11:30:30
     */
    public ResponseDTO<String> add(GearboxSpeedAddDTO addDTO) {
        GearboxSpeedEntity entity = SmartBeanUtil.copy(addDTO, GearboxSpeedEntity.class);
        gearboxSpeedDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author wuhq
     * @date 2022-05-27 11:30:30
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(GearboxSpeedUpdateDTO updateDTO) {
        GearboxSpeedEntity entity = SmartBeanUtil.copy(updateDTO, GearboxSpeedEntity.class);
        gearboxSpeedDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author wuhq
     * @date 2022-05-27 11:30:30
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        gearboxSpeedDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author wuhq
     * @date 2022-05-27 11:30:30
     */
    public List<GearboxSpeedExcelVO> queryAllExportData(GearboxSpeedQueryDTO queryDTO) {
        return gearboxSpeedDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author wuhq
     * @date 2022-05-27 11:30:30
     */
    public List<GearboxSpeedExcelVO> queryBatchExportData(List<Long> idList) {
        return gearboxSpeedDao.queryBatchExportData(idList);
    }

    public GearboxSpeedEntity getByGearboxId(Long gearboxId) {
        LambdaQueryWrapper<GearboxSpeedEntity> queryWrapper = new LambdaQueryWrapper<GearboxSpeedEntity>();
        queryWrapper.eq(GearboxSpeedEntity::getGearboxId, gearboxId);
        return gearboxSpeedDao.selectOne(queryWrapper);
    }

    public void delByGearboxId(Long gearboxId) {

        LambdaQueryWrapper<GearboxSpeedEntity> queryWrapper = new LambdaQueryWrapper<GearboxSpeedEntity>();
        queryWrapper.eq(GearboxSpeedEntity::getGearboxId, gearboxId);
        gearboxSpeedDao.delete(queryWrapper);

    }
}
